<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/8/2
  Time: 11:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <button onclick="ajaxGet()">ajax get</button>
    <button onclick="ajaxPost()">ajax post</button>
    <button onclick="ajax()">ajax</button>

    <script src="<%=request.getContextPath()%>/static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script>
        function ajaxGet() {
            //$.get(url, [data], [callback], [type])
            $.get(
                '<%=request.getContextPath()%>/ajax',
                {'name': '张三'},
                function(jsonObj) {
                    console.log(jsonObj);
                },
                'json'
            );

        }

        function ajaxPost() {
            $.post(
                '<%=request.getContextPath()%>/ajax',
                {'name': '张三1'},
                function(jsonObj) {
                    console.log(jsonObj);
                },
                'json'
            );
        }

        function ajax() {
            //$.ajax( { option1:value1,option2:value2... } );
            $.ajax({
                async: false,
                url: '<%=request.getContextPath()%>/ajax',
                type: 'GET',
                data: {'name': '王五'},
                success: function(jsonObj) {
                    console.log(jsonObj);
                },
                dataType: 'json'
            });
        }
    </script>
</body>
</html>
